# -*-coding:utf-8-*-
from utils import read_txt,cut_sent,read_hed,read_word
from Syntactic_Analysis import ParseResult


'''
把字句 细分类
'''

'''
判定条件
'''
def judge_type(hed_info, modifi_info, fenci_res, pos_res):
    mt_info = modifi_info['mt_info']  # MT成分
    pob_info = modifi_info['pob_info']  # POB成分
    adv_info = modifi_info['adv_info']  # ADV成分
    cmp_info = modifi_info['cmp_info']  # CMP成分
    vob_info = modifi_info['vob_info']  # VOB成分
    vv_info = modifi_info['vv_info']    # VV成分
    adv_h = read_hed(adv_info, hed_info['word'])  # 修饰HED的ADV成分


    type_lst = ['主||“把”+宾+动+“了/着”',
                '主||“把”+宾+动+补语',
                '主||“把”+宾+动+宾',
                '主||“把”+宾+状+动',
                '主||状+“把”+宾+动+其他成分',
                '主||（状+）“把”+宾+状+动+其他成分',
                '主||“把”+宾+“给”+动+其他成分',
                '其他句型']

    noun_lst = ['n', 'f', 's', 't', 'nr', 'ns', 'nt', 'nw', 'nz', 'r', 'an', 'vn', 'PER']
    verb_lst = ['v', 'vd', 'vn']
    adj_lst = ['a', 'ad', 'an']
    quan_lst = ['m', 'q']

    type_id = len(type_lst) - 1
    if read_word(pob_info,['把']):       # 把字句基本条件：“把”作为POB成分
        if [pob for pob in pob_info if fenci_res.index('把') < pob['num'] < hed_info['num']-1]:       # "把"+宾+动
            if '给' in fenci_res and fenci_res.index('给') > fenci_res.index('把'):
                type_id = 6
                return type_lst[type_id]
            if [adv for adv in adv_info if (fenci_res.index("把") < adv['num'] < hed_info['num'] - 1)]:  # “把”+宾+状+动
                type_id = 5
                return  type_lst[type_id]
            type_id = 3
            return type_lst[type_id]
        if [adv for adv in adv_info if (adv['num'] < fenci_res.index("把"))]:  # 状+“把”
            type_id = 4
            return type_lst[type_id]
        if [vob for vob in vob_info if vob['num'] > hed_info['num']-1]:     # 动词后有宾语
            type_id = 2
            return type_lst[type_id]
        if read_hed(cmp_info,hed_info['word']) and fenci_res.index(read_hed(cmp_info,hed_info['word'])['word']) > fenci_res.index(hed_info['word']):
            type_id = 1
            return type_lst[type_id]
        if read_word(mt_info,['着','了']):
            type_id = 0
            return type_lst[type_id]

    return type_lst[type_id]



if __name__ == '__main__':
    path = './data/test_ba.txt' #读取数据
    sentences = read_txt(path)
    for sent in sentences:
        print('*'*125)
        print(sent)
        fenci_res, pos_res, ddp_res = cut_sent(sent)
        pr = ParseResult(fenci_res, pos_res, ddp_res)
        print('分词：',fenci_res)
        print('词性：',pos_res)
        print('句法：',ddp_res)
        modifi_info = pr.get_modifi_info()
        hed_info = pr.get_hed_info()
        print(judge_type(hed_info,modifi_info,fenci_res, pos_res))
